package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.ConditionDTO;
import com.ra.pojo.dto.TagAdminDTO;
import com.ra.pojo.dto.TagDTO;
import com.ra.service.ITagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "标签模块")
public class TagController {

    @Autowired
    private ITagService tagService;

    @ApiOperation(value = "查询后台标签列表")
    @GetMapping("/admin/tags")
    public RespBean<RespPageBean<TagAdminDTO>> listTagsAdmin(ConditionDTO conditionDTO) {
        return RespBean.success(tagService.listTagsAdmin(conditionDTO));
    }

    @ApiOperation(value = "添加或修改标签")
    @PostMapping("/admin/tags")
    public RespBean<?> saveOrUpdateTag(@Valid @RequestBody TagDTO tagDTO) {
        tagService.saveOrUpdateTag(tagDTO);
        return RespBean.success();
    }
    @ApiOperation(value = "删除标签")
    @DeleteMapping("/admin/tags")
    public RespBean<?> deleteTag(@RequestBody List<Integer> tagsIdList) {
        tagService.delTag(tagsIdList);
        return RespBean.success();
    }
    @ApiOperation(value = "搜索文章标签")
    @PostMapping("/admin/tags/search")
    public RespBean<List<TagAdminDTO>> listTagsAdminBySearch(@RequestBody ConditionDTO conditionDTO) {
        return RespBean.success(tagService.listTagsAdminBySearch(conditionDTO));
    }

}

